package com.moon.controller;

import com.moon.pojo.Dept;
import com.moon.pojo.Result;
import com.moon.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @DeleteMapping
    public Result deleteById(Integer id,String name) {
        System.out.println("id:" + id + "name:" + name);
        return Result.success();
    }

    @PostMapping
    public Result addDept(@RequestBody Dept dept) {
        System.out.println(dept);
        deptService.addDept(dept);
        return Result.success();
    }

    @GetMapping("/{deptId}/{deptName}")
    public Result getDept(@PathVariable("deptId") Integer id,
                          @PathVariable String deptName) {
        System.out.println("id:" + id + "name:" + deptName);

        Dept dept = deptService.getDept(id, deptName);
        return Result.success(dept);
    }

    @PutMapping
    public Result updateDept(@RequestBody Dept dept) {
        deptService.update(dept);
        return Result.success();
    }


}
